﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApi.Core.Log;

namespace WebApi.Core.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TestLog4netController : ControllerBase
    {
        private readonly ILoggerHelper _logger;

        public TestLog4netController(ILoggerHelper logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// 测试日志
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult LogTest()
        {
            //bin\Debug\netcoreapp3.1\log
            _logger.Error(typeof(TestLog4netController), "这是错误日志", new Exception("123"));
            _logger.Debug(typeof(TestLog4netController), "这是bug日志");

            return Ok();
        }

        /// <summary>
        /// 抛出异常
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Throw()
        {
            throw new System.IO.IOException();
        }

    }
}